package com.das.mechanic_base.widget;

import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.das.mechanic_base.R;
import com.umeng.analytics.MobclickAgent;

import razerdp.basepopup.BasePopupWindow;
import razerdp.util.animation.AlphaConfig;
import razerdp.util.animation.AnimationHelper;

/**
 * 待办事项优先级弹窗
 */

public class X3TasklevelWindow extends BasePopupWindow implements View.OnClickListener, PopupWindow.OnDismissListener {

    private TextView tv_medium;
    private TextView tv_high;
    private TextView tv_low;

    private Context mContext;

    public X3TasklevelWindow(Context context) {
        super(context);
        this.mContext = context;
    }

    @Override
    public View onCreateContentView() {
        return createPopupById(R.layout.x3_popu_task_level);
    }

    @Override
    public void onViewCreated(View contentView) {
        MobclickAgent.onPageStart("待办事项优先级弹窗");
        tv_low = contentView.findViewById(R.id.tv_low);
        tv_medium = contentView.findViewById(R.id.tv_medium);
        tv_high = contentView.findViewById(R.id.tv_high);
        tv_medium.setOnClickListener(this);
        tv_high.setOnClickListener(this);
        tv_low.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        dismiss();
        int id = view.getId();
        if (id == R.id.tv_high) {
            if (iOnItemCameraClick != null) {
                iOnItemCameraClick.iOnClickTaskLevel("LEVEL_HI");
            }
        } else if (id == R.id.tv_medium) {
            if (iOnItemCameraClick != null) {
                iOnItemCameraClick.iOnClickTaskLevel("LEVEL_MI");
            }
        } else if (id == R.id.tv_low) {
            if (iOnItemCameraClick != null) {
                iOnItemCameraClick.iOnClickTaskLevel("NONTH");
            }
        }
    }

    IOpenCameraClick iOnItemCameraClick;

    public void setiOnItemCameraClick(IOpenCameraClick iOnItemCameraClick) {
        this.iOnItemCameraClick = iOnItemCameraClick;
    }

    @Override
    public void onDismiss() {
        MobclickAgent.onPageEnd("待办事项优先级弹窗");
        if (iOnItemCameraClick != null) {
            iOnItemCameraClick.onDissMissLevel();
        }
        super.onDismiss();
    }

    public interface IOpenCameraClick {

        void iOnClickTaskLevel(String status);

        void onDissMissLevel();
    }

    @Override
    protected Animation onCreateShowAnimation() {
        return AnimationHelper.asAnimation()
                .withAlpha(AlphaConfig.IN.duration(200))
                .toShow();
    }

    @Override
    protected Animation onCreateDismissAnimation() {
        return AnimationHelper.asAnimation()
                .withAlpha(AlphaConfig.OUT.duration(200))
                .toDismiss();
    }
}
